From c6d5f82456e834fe237fc962f33f6de62f111de2 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Fri, 15 Aug 2008 20:27:14 +0000 Subject: [PATCH] Add support (read) for MapAsia track files (.tr7). --- gpsbabel/Makefile.in | 4 +- gpsbabel/tr7.c | 121 +++++++++++++++++++++++++++++++++++++++++++ gpsbabel/vecs.c | 7 +++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 gpsbabel/tr7.c diff --git a/gpsbabel/Makefile.in b/gpsbabel/Makefile.in index 90bfb9752..2bf3f766e 100644 --- a/gpsbabel/Makefile.in +++ b/gpsbabel/Makefile.in @@ -59,7 +59,7 @@ ALL_FMTS=$(MINIMAL_FMTS) gtm.o gpsutil.o pcx.o cetus.o copilot.o \ wbt-200.o stmsdf.o gtrnctr.o dmtlog.o raymarine.o alan.o vitovtt.o \ ggv_log.o g7towin.o garmin_gpi.o lmx.o random.o xol.o dg-100.o \ navilink.o mtk_logger.o ik3d.o osm.o destinator.o exif.o vidaone.o \ - igo8.o gopal.o humminbird.o + igo8.o gopal.o humminbird.o tr7.o FMTS=@FMTS@ @@ -745,6 +745,8 @@ tpo.o: tpo.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \ jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \ jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h +tr7.o: tr7.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ + zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h csv_util.h trackfilter.o: trackfilter.c defs.h config.h queue.h gbtypes.h \ zlib/zlib.h zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h \ filterdefs.h strptime.h grtcirc.h diff --git a/gpsbabel/tr7.c b/gpsbabel/tr7.c new file mode 100644 index 000000000..99d4f9700 --- /dev/null +++ b/gpsbabel/tr7.c @@ -0,0 +1,121 @@ +/* + + Support for MapAsia (.tr7) track file format. + + Copyright (C) 2008 Olaf Klein, o.b.klein@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include +#include +#include +#include +#include "defs.h" +#include "jeeps/gpsmath.h" + +#define MYNAME "tr7" + +#define TR7_TRACK_MAGIC 0x223eadb + +static +arglist_t tr7_args[] = { + ARG_TERMINATOR +}; + +static gbfile *fin; + +/******************************************************************************* +* %%% global callbacks called by gpsbabel main process %%% * +*******************************************************************************/ + +static void +tr7_rd_init(const char *fname) +{ + fin = gbfopen_le(fname, "rb", MYNAME); +} + +static void +tr7_rd_deinit(void) +{ + gbfclose(fin); +} + +static void +tr7_read(void) +{ + unsigned char buff[32]; + waypoint *wpt; + route_head *trk = NULL; + unsigned int magic; + + magic = gbfgetint32(fin); + if (magic != TR7_TRACK_MAGIC) { + fatal(MYNAME ": Invalid magic number in header (%X, but %X expected)!\n", magic, TR7_TRACK_MAGIC); + } + + while (! gbfeof(fin)) { + gbfread(buff, 1, sizeof(buff), fin); + if (buff[0] == 0xD8) { + struct tm tm; + double lat, lon; + + lat = (double)le_read32(&buff[20]) / 1000000.0; + lon = (double)le_read32(&buff[16]) / 1000000.0; + if ((fabs(lat) > 90) || (fabs(lon) > 180)) continue; + + memset(&tm, 0, sizeof(tm)); + tm.tm_hour = buff[8]; + tm.tm_min = buff[10]; + tm.tm_sec = buff[12]; + + wpt = waypt_new(); + + wpt->latitude = lat; + wpt->longitude = lon; + wpt->creation_time = mkgmtime(&tm); + + if (! trk) { + trk = route_head_alloc(); + track_add_head(trk); + } + track_add_wpt(trk, wpt); + } + } +} + +/**************************************************************************/ + +ff_vecs_t tr7_vecs = { /* currently we can only read tracks */ + ff_type_internal, + { + ff_cap_none /* waypoints */, + ff_cap_read /* tracks */, + ff_cap_none /* routes */ + }, + tr7_rd_init, + NULL, + tr7_rd_deinit, + NULL, + tr7_read, + NULL, + NULL, + tr7_args, + CET_CHARSET_ASCII, 0 + +}; + +/**************************************************************************/ diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index 29e38f8ae..f2e2db362 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -142,6 +142,7 @@ extern ff_vecs_t exif_vecs; extern ff_vecs_t vidaone_vecs; extern ff_vecs_t gopal_vecs; extern ff_vecs_t humminbird_vecs; +extern ff_vecs_t tr7_vecs; static vecs_t vec_list[] = { @@ -809,6 +810,12 @@ vecs_t vec_list[] = { "Humminbird waypoints (.hwr)", "hwr" }, + { + &tr7_vecs, + "tr7", + "MapAsia track file (.tr7)", + "tr7" + }, #endif // MAXIMAL_ENABLED { NULL, -- 2.30.2